/**
 * @(#)Coordinate.java
 *
 *
 * @author Mark Vimonte
 * @version 1.00 2008/2/25
 * Yes RLB! i am THE MAN
 * woot!
 * ANYWAYS ive made like 3 coordinate classes in the last week so i decided to make one official
 * -MAV
 */
package gamefiles;

import java.util.*;

public class Coordinate extends Object
	{
	/*
	 * Constructs an Coordinate object with specified x and y positions
	 * 
	 * @param xC the x coordinate of the Coordinate object 
	 * @param yC the y coordinate of the Coordinate object 
	 * @exception throws Illegal Argument exceptions if the coordinates
	 * are outside of thw viewable window.
	 */
    public Coordinate(int xC, int yC) 
    	{
    	super();
    	if(xC > MAX_X)
			throw new IllegalArgumentException("Illegal X Coordinate: " 
			+ "Out of Display");
		if(xC < MIN_X)
			throw new IllegalArgumentException("Illegal X Coordinate: " 
			+ "Out of Display");
		if(yC > MAX_Y)
			throw new IllegalArgumentException("Illegal Y Coordinate: " 
			+ "Out of Display");
		if(yC < MIN_Y)
			throw new IllegalArgumentException("Illegal Y Coordinate: " 
			+ "Out of Display");											
    	x = xC;
    	y = yC;
    	}
    /* 
 	 * Input the min and max X and Y values for the graph you are making coordinates for
 	 * then input how many boxes you want on the sides
 	 * it will then return to you an array of coordinates that have a center in each of the
 	 * squares. Yes this makes sense to me - MAV
 	 */ 
    public static ArrayList<Coordinate> getArrayList(int xMin, int xMax,
     int yMin, int yMax, int numberPerSide)
     	{
     	int xSpan = Math.abs(xMin) + Math.abs(xMax);
     	int ySpan = Math.abs(yMax) + Math.abs(yMin);
     	if(xMin == xMax || yMin == yMax)
			throw new IllegalArgumentException("Illegal X or Values: " +
            		"Equal min and max values");
		if(xSpan < numberPerSide || ySpan < numberPerSide)
			throw new IllegalArgumentException("Illegal Number of Sides: " +
            		"Cannot have a box with an X or Y less than 1");                        
     	ArrayList<Coordinate> zz = new ArrayList<Coordinate>(numberPerSide*numberPerSide);
     	int xAmountPerSq = xSpan/numberPerSide;
     	int yAmountPerSq = ySpan/numberPerSide;
     	int xIncrement = xAmountPerSq;
     	int yIncrement = yAmountPerSq;
     	for (int i = 0, xStart = xMin + xIncrement/2, yStart = 
                yMax - yIncrement/2; i < numberPerSide * numberPerSide; i++)
     		{
     		zz.add(new Coordinate(xStart,yStart));
     		if ((i + 1) % numberPerSide == 0)
				{
				yStart -= yIncrement;
				xStart = xMin + xIncrement/2;
				}
			else
				xStart += xIncrement;
		}
     	return zz;
     	}
    /*
     * Accessor function that returns x coordinate
     */
    public int getX()
    	{
    	return x;
    	}
    /*
     * Accessor function that returns y coordinate
     */
    public int getY()
    	{
    	return y;
    	}
    public void inputX(int xIn)
    	{
    	x = xIn;
    	}
    public void inputY(int yIn)
    	{
    	y = yIn;
    	}
    /*
     * toString override that displays the coordinates of the
     * Coordinate object.
     */
    public String toString()
    	{
    	return "My X coordinate is " + x + " and my Y coordinate is " + y + ".";
    	}
    private int x;
    private int y;
    public static final int MAX_X = 300;
    public static final int MAX_Y = 300;
    public static final int MIN_X = -300;
    public static final int MIN_Y = -300;
    public static final int DEFAULT_RADIUS = 30;
    public static final int MAX_PEN_WIDTH = 3;
    public static final int MIN_PEN_WIDTH = 1;
	}